<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>使用组件的细节点</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <!-- <div id="app">
        <table>
            <tbody>
                <tr is="row"></tr>
                <tr is="row"></tr>
                <tr is="row"></tr>
            </tbody>
        </table>
    </div>

    <script>
        Vue.component('row', {
            data: function() {
                return {
                    content: 'this is a content'
                }
            },
            template: '<tr><td>{{content}}</td></tr>'
        })
        var vm = new Vue({
            el: '#app'
        })
    </script> -->


    <!-- <div id="app">
        <div
            ref='hello' 
            @click="handleClick"
        >
            Hello World
        </div>
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            methods: {
                handleClick: function() {
                    console.log(this.$refs.hello.innerHTML);
                }
            }
        })
    </script> -->


    <div id="app">
        <counter ref="one" @change="handleChange"></counter>
        <counter ref="two" @change="handleChange"></counter>
        <div>{{total}}</div>
    </div>

    <script>
        Vue.component('counter', {
            template: '<div @click="handleClick">{{number}}</div>',
            data: function() {
                return {
                    number: 0
                }
            },
            methods: {
                handleClick: function() {
                    this.number ++;
                    this.$emit('change');
                }
            },
        })
        var vm = new Vue({
            el: '#app',
            data: {
                total: 0
            },
            methods: {
                handleChange: function() {
                    this.total = this.$refs.one.number + this.$refs.two.number;
                }
            }
        })
    </script>
</body>
</html>